import time
import unittest

from _init_ import TestCaseOne
from selenium import webdriver
from selenium.webdriver.common.by import By
# from unittest import TestCase
from ddt import ddt, data, unpack
from method import method

da1 = [
    ['lisi', 123456, "666666"]
]
da2 = [
    ['lisi', 123456, "666667"]
]
da3 = [
    ['lisi4', 123456, "666666"]
]
da4 = [
    ['lisi5', 123456, "666666"]
]
da5 = da1
da6 = da2
da7 = da3
da8 = da4
da9 = da1
da10 = da2
da11 = da3
da12 = da4
da13 = [
    ['lisi6', 123456, "666667"]
]
da14 = [
    ['lisi7', 123456, "666666"]
]
da15 = [
    ['lisi7', 123456, "666666"]
]
da16 = [
    ['lisi5', 123456, "666666"]
]


# 选择跳过的方法
def chooseSkip(get_skip_or_no_skip, get_choose_case):
    all_test = []
    for i in range(1, 17):
        all_test.append(i)
    for j in get_choose_case:
        all_test.remove(j)
    if get_skip_or_no_skip == 1:
        the_choose_skip = all_test
    else:
        the_choose_skip = get_choose_case
    return the_choose_skip


# 选择跳过所选用例则选择0，选择执行所选用例则选择1
skip_or_no_skip = 0
choose_case = []
choose_skip = chooseSkip(skip_or_no_skip, choose_case)
s = method()
# 创建一个列表用来存储选择，有多少方法就准备多少元素
skip_test = s.skipTest(16, choose_skip)
d = 1234567890123456


@ddt
class TestBankcard(TestCaseOne):
    @unittest.skipIf(skip_test[0] == 1, '暂时跳过')
    @data(*da1)
    @unpack
    def test_001_PurchaseFund(self, a, b, c):
        # 清理数据库，准备测试数据
        t = s.findUsername(a)
        if len(t) != 0:
            s.cleanDatabaseByUsername(a)
            s.addUsername(a)
        else:
            s.addUsername(a)
        p = len(s.findBankcardByNum(d))
        userid = s.findIdByUserame(a)
        if p == 0:
            s.addCompleteBankcard("中国银行", d, userid, 1000000)
        else:
            s.cleanCardByNum(d)
            s.addCompleteBankcard("中国银行", d, userid, 1000000)
        s.setDefaultPayCard(userid, d)

        driver = webdriver.Chrome()

        driver.get("http://localhost:90/")

        driver.maximize_window()

        # 正常登录
        # 输入用户名
        driver.find_element(By.XPATH, "//input[@id='username']").send_keys(a)

        #  输入密码
        driver.find_element(By.XPATH, "//input[@id='password']").send_keys(b)

        # 点击登陆
        driver.find_element(By.XPATH, "//button[@id='login_btn']").click()
        time.sleep(1)

        # 点击个人理财
        driver.find_element(By.XPATH, "//i[@class='mdi mdi-square-inc-cash']").click()
        time.sleep(1)

        # 点击零钱理财
        driver.find_element(By.LINK_TEXT, "零钱理财").click()
        time.sleep(1)

        # 点击支付宝投资
        driver.find_element(By.XPATH, "//button[@buybtnname='支付宝零钱理财']").click()
        time.sleep(2)

        # 输入支付密码
        driver.find_element(By.CSS_SELECTOR, ".layui-layer-content > #password").send_keys(c)
        time.sleep(1)

        # 点击确定
        driver.find_element(By.XPATH, "//a[@class='layui-layer-btn0']").click()
        time.sleep(2)

        #  获取实际标题结果
        result1 = driver.find_element(By.XPATH, "//div[@class='jconfirm-content']/div").text
        result2 = s.findBalanceByCardNum(d)
        expected = "((Decimal('999900.00'),),)"
        # 判断银行卡名称是否在列表中
        flag = True
        if result1 == "买入成功!" and str(result2) == expected:
            print("用例通过！")
        else:
            print("用例不通过！")
            screenshot = s.failedScreenshotNamed("test_001_PurchaseFund")
            driver.save_screenshot(screenshot)
            flag = False
        time.sleep(3)

        driver.close()

        time.sleep(1)

        self.assertEqual(True, flag)

    @unittest.skipIf(skip_test[1] == 1, '暂时跳过')
    @data(*da2)
    @unpack
    def test_002_PurchaseFundWrongPwd(self, a, b, c):
        # 清理数据库，准备测试数据
        t = s.findUsername(a)
        if len(t) != 0:
            s.cleanDatabaseByUsername(a)
            s.addUsername(a)
        else:
            s.addUsername(a)
        p = len(s.findBankcardByNum(d))
        userid = s.findIdByUserame(a)
        if p == 0:
            s.addCompleteBankcard("中国银行", d, userid, 1000000)
        else:
            s.cleanCardByNum(d)
            s.addCompleteBankcard("中国银行", d, userid, 1000000)
        s.setDefaultPayCard(userid, d)

        driver = webdriver.Chrome()

        driver.get("http://localhost:90/")

        driver.maximize_window()

        # 正常登录
        # 输入用户名
        driver.find_element(By.XPATH, "//input[@id='username']").send_keys(a)

        #  输入密码
        driver.find_element(By.XPATH, "//input[@id='password']").send_keys(b)

        # 点击登陆
        driver.find_element(By.XPATH, "//button[@id='login_btn']").click()
        time.sleep(1)

        # 点击个人理财
        driver.find_element(By.XPATH, "//i[@class='mdi mdi-square-inc-cash']").click()
        time.sleep(1)

        # 点击零钱理财
        driver.find_element(By.LINK_TEXT, "零钱理财").click()
        time.sleep(1)

        # 点击支付宝投资
        driver.find_element(By.XPATH, "//button[@buybtnname='支付宝零钱理财']").click()
        time.sleep(2)

        # 输入支付密码
        driver.find_element(By.CSS_SELECTOR, ".layui-layer-content > #password").send_keys(c)
        time.sleep(1)

        # 点击确定
        driver.find_element(By.XPATH, "//a[@class='layui-layer-btn0']").click()
        time.sleep(2)

        #  获取实际标题结果
        result = driver.find_element(By.XPATH, "//div[@class='jconfirm-content']/div").text

        # 判断结果是否为买入失败
        if result == "买入失败!":
            print("用例通过！")
        else:
            print("用例不通过！")
            screenshot = s.failedScreenshotNamed("test_002_PurchaseFundWrongPwd")
            driver.save_screenshot(screenshot)

        time.sleep(3)

        driver.close()

        time.sleep(2)

        self.assertEqual("买入失败!", result)

    @unittest.skipIf(skip_test[2] == 1, '暂时跳过')
    @data(*da3)
    @unpack
    def test_003_PurchaseFundNoMoney(self, a, b, c):
        # 清理数据库，准备测试数据
        t = s.findUsername(a)
        if len(t) != 0:
            s.cleanDatabaseByUsername(a)
            s.addUsername(a)
        else:
            s.addUsername(a)
        p = len(s.findBankcardByNum(d))
        userid = s.findIdByUserame(a)
        if p == 0:
            s.addCompleteBankcard("中国银行", d, userid, 99)
        else:
            s.cleanCardByNum(d)
            s.addCompleteBankcard("中国银行", d, userid, 99)
        s.setDefaultPayCard(userid, d)

        driver = webdriver.Chrome()

        driver.get("http://localhost:90/")

        driver.maximize_window()

        # 正常登录
        # 输入用户名
        driver.find_element(By.XPATH, "//input[@id='username']").send_keys(a)

        #  输入密码
        driver.find_element(By.XPATH, "//input[@id='password']").send_keys(b)

        # 点击登陆
        driver.find_element(By.XPATH, "//button[@id='login_btn']").click()
        time.sleep(1)

        # 点击个人理财
        driver.find_element(By.XPATH, "//i[@class='mdi mdi-square-inc-cash']").click()
        time.sleep(1)

        # 点击零钱理财
        driver.find_element(By.LINK_TEXT, "零钱理财").click()
        time.sleep(1)

        # 点击支付宝投资
        driver.find_element(By.XPATH, "//button[@buybtnname='支付宝零钱理财']").click()
        time.sleep(2)

        # 输入支付密码
        driver.find_element(By.CSS_SELECTOR, ".layui-layer-content > #password").send_keys(c)
        time.sleep(1)

        # 点击确定
        driver.find_element(By.XPATH, "//a[@class='layui-layer-btn0']").click()
        time.sleep(2)

        #  获取实际标题结果
        result = driver.find_element(By.XPATH, "//div[@class='jconfirm-content']/div").text

        # 判断“买入失败”是否在结果中
        if "买入失败!" in result:
            print("用例通过！")
        else:
            print("用例不通过！")
            screenshot = s.failedScreenshotNamed("test_003_PurchaseFundNoMoney")
            driver.save_screenshot(screenshot)

        time.sleep(3)

        driver.close()

        time.sleep(2)

        self.assertIn("买入失败!", result)

    @unittest.skipIf(skip_test[3] == 1, '暂时跳过')
    @data(*da4)
    @unpack
    def test_004_PurchaseWithOutCard(self, a, b, c):
        # 清理数据库，准备测试数据
        t = s.findUsername(a)
        if len(t) != 0:
            s.cleanDatabaseByUsername(a)
            s.addUsername(a)
        else:
            s.addUsername(a)
        userid = s.findIdByUserame(a)
        p = len(s.findBankcardById(userid))
        if p != 0:
            s.cleanCardById(userid)

        driver = webdriver.Chrome()

        driver.get("http://localhost:90/")

        driver.maximize_window()

        # 正常登录
        # 输入用户名
        driver.find_element(By.XPATH, "//input[@id='username']").send_keys(a)

        #  输入密码
        driver.find_element(By.XPATH, "//input[@id='password']").send_keys(b)

        # 点击登陆
        driver.find_element(By.XPATH, "//button[@id='login_btn']").click()
        time.sleep(1)

        # 点击个人理财
        driver.find_element(By.XPATH, "//i[@class='mdi mdi-square-inc-cash']").click()
        time.sleep(1)

        # 点击零钱理财
        driver.find_element(By.LINK_TEXT, "零钱理财").click()
        time.sleep(1)

        # 点击支付宝投资
        driver.find_element(By.XPATH, "//button[@buybtnname='支付宝零钱理财']").click()
        time.sleep(2)

        # 输入支付密码
        driver.find_element(By.CSS_SELECTOR, ".layui-layer-content > #password").send_keys(c)
        time.sleep(1)

        # 点击确定
        driver.find_element(By.XPATH, "//a[@class='layui-layer-btn0']").click()
        time.sleep(2)

        #  获取实际标题结果
        result = driver.find_element(By.XPATH, "//div[@class='jconfirm-content']/div").text

        # 判断银行卡名称是否在列表中
        if "请绑定银行卡" in result:
            print("用例通过！")
        else:
            print("用例不通过！")
            screenshot = s.failedScreenshotNamed("test_004_PurchaseWithOutCard")
            driver.save_screenshot(screenshot)

        time.sleep(3)

        driver.close()

        time.sleep(2)

        self.assertIn("请绑定银行卡", result)

    @unittest.skipIf(skip_test[4] == 1, '暂时跳过')
    @data(*da5)
    @unpack
    def test_005_termFinancialSuccess(self, a, b, c):
        # 清理数据库，准备测试数据
        t = s.findUsername(a)
        if len(t) != 0:
            s.cleanDatabaseByUsername(a)
            s.addUsername(a)
        else:
            s.addUsername(a)
        p = len(s.findBankcardByNum(d))
        userid = s.findIdByUserame(a)
        if p == 0:
            s.addCompleteBankcard("中国银行", d, userid, 1000000)
        else:
            s.cleanCardByNum(d)
            s.addCompleteBankcard("中国银行", d, userid, 1000000)
        s.setDefaultPayCard(userid, d)

        driver = webdriver.Chrome()

        driver.get("http://localhost:90/")

        driver.maximize_window()

        # 正常登录
        # 输入用户名
        driver.find_element(By.XPATH, "//input[@id='username']").send_keys(a)

        #  输入密码
        driver.find_element(By.XPATH, "//input[@id='password']").send_keys(b)

        # 点击登陆
        driver.find_element(By.XPATH, "//button[@id='login_btn']").click()
        time.sleep(1)

        # 点击个人理财
        driver.find_element(By.XPATH, "//i[@class='mdi mdi-square-inc-cash']").click()
        time.sleep(1)

        # 点击期限理财
        driver.find_element(By.LINK_TEXT, "期限理财").click()
        time.sleep(1)

        # 点击支付宝期限理财
        driver.find_element(By.XPATH, "//button[@buybtnname='支付宝期限理财']").click()
        time.sleep(2)

        # 输入支付密码
        driver.find_element(By.CSS_SELECTOR, ".layui-layer-content > #password").send_keys(c)
        time.sleep(1)

        # 点击确定
        driver.find_element(By.XPATH, "//a[@class='layui-layer-btn0']").click()
        time.sleep(2)

        #  获取实际标题结果
        result1 = driver.find_element(By.XPATH, "//div[@class='jconfirm-content']/div").text
        result2 = s.findBalanceByCardNum(d)
        expected = "((Decimal('999900.00'),),)"
        # 判断银行卡名称是否在列表中
        flag = True
        if result1 == "买入成功!" and str(result2) == expected:
            print("用例通过！")
        else:
            print("用例不通过！")
            screenshot = s.failedScreenshotNamed("test_005_termFinancialSuccess")
            driver.save_screenshot(screenshot)
            flag = False
        time.sleep(3)

        driver.close()

        time.sleep(1)

        self.assertEqual(True, flag)

        driver.close()

    @unittest.skipIf(skip_test[5] == 1, '暂时跳过')
    @data(*da6)
    @unpack
    def test_006_termFinancialWrongPwd(self, a, b, c):
        # 清理数据库，准备测试数据
        t = s.findUsername(a)
        if len(t) != 0:
            s.cleanDatabaseByUsername(a)
            s.addUsername(a)
        else:
            s.addUsername(a)
        p = len(s.findBankcardByNum(d))
        userid = s.findIdByUserame(a)
        if p == 0:
            s.addCompleteBankcard("中国银行", d, userid, 1000000)
        else:
            s.cleanCardByNum(d)
            s.addCompleteBankcard("中国银行", d, userid, 1000000)
        s.setDefaultPayCard(userid, d)

        driver = webdriver.Chrome()

        driver.get("http://localhost:90/")

        driver.maximize_window()

        # 正常登录
        # 输入用户名
        driver.find_element(By.XPATH, "//input[@id='username']").send_keys(a)

        #  输入密码
        driver.find_element(By.XPATH, "//input[@id='password']").send_keys(b)

        # 点击登陆
        driver.find_element(By.XPATH, "//button[@id='login_btn']").click()
        time.sleep(1)

        # 点击个人理财
        driver.find_element(By.XPATH, "//i[@class='mdi mdi-square-inc-cash']").click()
        time.sleep(1)

        # 点击期限理财
        driver.find_element(By.LINK_TEXT, "期限理财").click()
        time.sleep(1)

        # 点击支付宝期限理财
        driver.find_element(By.XPATH, "//button[@buybtnname='支付宝期限理财']").click()
        time.sleep(2)

        # 输入支付密码
        driver.find_element(By.CSS_SELECTOR, ".layui-layer-content > #password").send_keys(c)
        time.sleep(1)

        # 点击确定
        driver.find_element(By.XPATH, "//a[@class='layui-layer-btn0']").click()
        time.sleep(2)

        #  获取实际标题结果
        result = driver.find_element(By.XPATH, "//div[@class='jconfirm-content']/div").text

        if "买入失败" in result:
            print("用例通过！")
        else:
            print("用例不通过！")
            screenshot = s.failedScreenshotNamed("test_006_termFinancialWrongPwd")
            driver.save_screenshot(screenshot)

        time.sleep(3)

        driver.close()

        time.sleep(1)

        self.assertIn("买入失败", result)

    @unittest.skipIf(skip_test[6] == 1, '暂时跳过')
    @data(*da7)
    @unpack
    def test_007_termFinancialNoMoney(self, a, b, c):
        # 清理数据库，准备测试数据
        t = s.findUsername(a)
        if len(t) != 0:
            s.cleanDatabaseByUsername(a)
            s.addUsername(a)
        else:
            s.addUsername(a)
        p = len(s.findBankcardByNum(d))
        userid = s.findIdByUserame(a)
        if p == 0:
            s.addCompleteBankcard("中国银行", d, userid, 99)
        else:
            s.cleanCardByNum(d)
            s.addCompleteBankcard("中国银行", d, userid, 99)
        s.setDefaultPayCard(userid, d)

        driver = webdriver.Chrome()

        driver.get("http://localhost:90/")

        driver.maximize_window()

        # 正常登录
        # 输入用户名
        driver.find_element(By.XPATH, "//input[@id='username']").send_keys(a)

        #  输入密码
        driver.find_element(By.XPATH, "//input[@id='password']").send_keys(b)

        # 点击登陆
        driver.find_element(By.XPATH, "//button[@id='login_btn']").click()
        time.sleep(1)

        # 点击个人理财
        driver.find_element(By.XPATH, "//i[@class='mdi mdi-square-inc-cash']").click()
        time.sleep(1)

        # 点击期限理财
        driver.find_element(By.LINK_TEXT, "期限理财").click()
        time.sleep(1)

        # 点击支付宝期限理财
        driver.find_element(By.XPATH, "//button[@buybtnname='支付宝期限理财']").click()
        time.sleep(2)

        # 输入支付密码
        driver.find_element(By.CSS_SELECTOR, ".layui-layer-content > #password").send_keys(c)
        time.sleep(1)

        # 点击确定
        driver.find_element(By.XPATH, "//a[@class='layui-layer-btn0']").click()
        time.sleep(2)

        #  获取实际标题结果
        result = driver.find_element(By.XPATH, "//div[@class='jconfirm-content']/div").text

        if "买入失败" in result:
            print("用例通过！")
        else:
            print("用例不通过！")
            screenshot = s.failedScreenshotNamed("test_007_termFinancialNoMoney")
            driver.save_screenshot(screenshot)

        time.sleep(3)

        driver.close()

        time.sleep(1)

        self.assertIn("买入失败", result)

    @unittest.skipIf(skip_test[7] == 1, '暂时跳过')
    @data(*da8)
    @unpack
    def test_008_termFinancialNoCard(self, a, b, c):
        # 清理数据库，准备测试数据
        t = s.findUsername(a)
        if len(t) != 0:
            s.cleanDatabaseByUsername(a)
            s.addUsername(a)
        else:
            s.addUsername(a)
        userid = s.findIdByUserame(a)
        p = len(s.findBankcardById(userid))
        if p != 0:
            s.cleanCardById(userid)

        driver = webdriver.Chrome()

        driver.get("http://localhost:90/")

        driver.maximize_window()

        # 正常登录
        # 输入用户名
        driver.find_element(By.XPATH, "//input[@id='username']").send_keys(a)

        #  输入密码
        driver.find_element(By.XPATH, "//input[@id='password']").send_keys(b)

        # 点击登陆
        driver.find_element(By.XPATH, "//button[@id='login_btn']").click()
        time.sleep(1)

        # 点击个人理财
        driver.find_element(By.XPATH, "//i[@class='mdi mdi-square-inc-cash']").click()
        time.sleep(1)

        # 点击期限理财
        driver.find_element(By.LINK_TEXT, "期限理财").click()
        time.sleep(1)

        # 点击支付宝期限理财
        driver.find_element(By.XPATH, "//button[@buybtnname='支付宝期限理财']").click()
        time.sleep(2)

        # 输入支付密码
        driver.find_element(By.CSS_SELECTOR, ".layui-layer-content > #password").send_keys(c)
        time.sleep(1)

        # 点击确定
        driver.find_element(By.XPATH, "//a[@class='layui-layer-btn0']").click()
        time.sleep(2)

        #  获取实际标题结果
        result = driver.find_element(By.XPATH, "//div[@class='jconfirm-content']/div").text

        # 还需要判断余额，后续添加
        if "请绑定银行卡" in result:
            print("用例通过！")
        else:
            print("用例不通过！")
            screenshot = s.failedScreenshotNamed("test_008_termFinancialNoCard")
            driver.save_screenshot(screenshot)

        time.sleep(3)

        driver.close()

        time.sleep(1)

        self.assertIn("请绑定银行卡", result)

    @unittest.skipIf(skip_test[8] == 1, '暂时跳过')
    @data(*da9)
    @unpack
    def test_009_fundProductSuccess(self, a, b, c):
        # 清理数据库，准备测试数据
        t = s.findUsername(a)
        if len(t) != 0:
            s.cleanDatabaseByUsername(a)
            s.addUsername(a)
        else:
            s.addUsername(a)
        p = len(s.findBankcardByNum(d))
        userid = s.findIdByUserame(a)
        if p == 0:
            s.addCompleteBankcard("中国银行", d, userid, 1000000)
        else:
            s.cleanCardByNum(d)
            s.addCompleteBankcard("中国银行", d, userid, 1000000)
        s.setDefaultPayCard(userid, d)

        driver = webdriver.Chrome()

        driver.get("http://localhost:90/")

        driver.maximize_window()

        # 正常登录
        # 输入用户名
        driver.find_element(By.XPATH, "//input[@id='username']").send_keys(a)

        #  输入密码
        driver.find_element(By.XPATH, "//input[@id='password']").send_keys(b)

        # 点击登陆
        driver.find_element(By.XPATH, "//button[@id='login_btn']").click()
        time.sleep(1)

        # 点击个人理财
        driver.find_element(By.XPATH, "//i[@class='mdi mdi-square-inc-cash']").click()
        time.sleep(1)

        # 点击基金理财
        driver.find_element(By.LINK_TEXT, "基金理财").click()
        time.sleep(1)

        # 点击支付宝期限理财
        driver.find_element(By.XPATH, "//button[@buybtnname='广发多元新兴股票']").click()
        time.sleep(2)

        # 输入支付密码
        driver.find_element(By.CSS_SELECTOR, ".layui-layer-content > #password").send_keys(c)
        time.sleep(1)

        # 点击确定
        driver.find_element(By.XPATH, "//a[@class='layui-layer-btn0']").click()
        time.sleep(2)

        #  获取实际标题结果
        result = driver.find_element(By.XPATH, "//div[@class='jconfirm-content']/div").text

        if "买入成功" in result:
            print("用例通过！")
        else:
            print("用例不通过！")
            screenshot = s.failedScreenshotNamed("test_009_fundProductSuccess")
            driver.save_screenshot(screenshot)

        time.sleep(3)

        driver.close()

        time.sleep(1)

        self.assertIn("买入成功!", result)

    @unittest.skipIf(skip_test[9] == 1, '暂时跳过')
    @data(*da10)
    @unpack
    def test_010_FundProductWrongPwd(self, a, b, c):
        # 清理数据库，准备测试数据
        t = s.findUsername(a)
        if len(t) != 0:
            s.cleanDatabaseByUsername(a)
            s.addUsername(a)
        else:
            s.addUsername(a)
        p = len(s.findBankcardByNum(d))
        userid = s.findIdByUserame(a)
        if p == 0:
            s.addCompleteBankcard("中国银行", d, userid, 1000000)
        else:
            s.cleanCardByNum(d)
            s.addCompleteBankcard("中国银行", d, userid, 1000000)
        s.setDefaultPayCard(userid, d)

        driver = webdriver.Chrome()

        driver.get("http://localhost:90/")

        driver.maximize_window()

        # 正常登录
        # 输入用户名
        driver.find_element(By.XPATH, "//input[@id='username']").send_keys(a)

        #  输入密码
        driver.find_element(By.XPATH, "//input[@id='password']").send_keys(b)

        # 点击登陆
        driver.find_element(By.XPATH, "//button[@id='login_btn']").click()
        time.sleep(1)

        # 点击个人理财
        driver.find_element(By.XPATH, "//i[@class='mdi mdi-square-inc-cash']").click()
        time.sleep(1)

        # 点击基金理财
        driver.find_element(By.LINK_TEXT, "基金理财").click()
        time.sleep(1)

        # 点击广发多元新兴股票
        driver.find_element(By.XPATH, "//button[@buybtnname='广发多元新兴股票']").click()
        time.sleep(2)

        # 输入支付密码
        driver.find_element(By.CSS_SELECTOR, ".layui-layer-content > #password").send_keys(c)
        time.sleep(1)

        # 点击确定
        driver.find_element(By.XPATH, "//a[@class='layui-layer-btn0']").click()
        time.sleep(2)

        #  获取实际标题结果
        result = driver.find_element(By.XPATH, "//div[@class='jconfirm-content']/div").text
        # print(len(driver.find_elements(By.XPATH, "//div[@class='jconfirm-content']")))

        # 还需要判断余额，后续添加
        if "买入失败" in result:
            print("用例通过！")
        else:
            print("用例不通过！")
            screenshot = s.failedScreenshotNamed("test_010_FundProductWrongPwd")
            driver.save_screenshot(screenshot)

        time.sleep(3)

        driver.close()

        time.sleep(1)

        self.assertIn("买入失败", result)

    @unittest.skipIf(skip_test[10] == 1, '暂时跳过')
    @data(*da11)
    @unpack
    def test_011_FundProductNoMoney(self, a, b, c):
        # 清理数据库，准备测试数据
        t = s.findUsername(a)
        if len(t) != 0:
            s.cleanDatabaseByUsername(a)
            s.addUsername(a)
        else:
            s.addUsername(a)
        p = len(s.findBankcardByNum(d))
        userid = s.findIdByUserame(a)
        if p == 0:
            s.addCompleteBankcard("中国银行", d, userid, 99)
        else:
            s.cleanCardByNum(d)
            s.addCompleteBankcard("中国银行", d, userid, 99)
        s.setDefaultPayCard(userid, d)

        driver = webdriver.Chrome()

        driver.get("http://localhost:90/")

        driver.maximize_window()

        # 正常登录
        # 输入用户名
        driver.find_element(By.XPATH, "//input[@id='username']").send_keys(a)

        #  输入密码
        driver.find_element(By.XPATH, "//input[@id='password']").send_keys(b)

        # 点击登陆
        driver.find_element(By.XPATH, "//button[@id='login_btn']").click()
        time.sleep(1)

        # 点击个人理财
        driver.find_element(By.XPATH, "//i[@class='mdi mdi-square-inc-cash']").click()
        time.sleep(1)

        # 点击基金理财
        driver.find_element(By.LINK_TEXT, "基金理财").click()
        time.sleep(1)

        # 点击广发多元新兴股票
        driver.find_element(By.XPATH, "//button[@buybtnname='广发多元新兴股票']").click()
        time.sleep(2)

        # 输入支付密码
        driver.find_element(By.CSS_SELECTOR, ".layui-layer-content > #password").send_keys(c)
        time.sleep(1)

        # 点击确定
        driver.find_element(By.XPATH, "//a[@class='layui-layer-btn0']").click()
        time.sleep(2)

        #  获取实际标题结果
        result = driver.find_element(By.XPATH, "//div[@class='jconfirm-content']/div").text

        # 还需要判断余额，后续添加
        if "买入失败" in result:
            print("用例通过！")
        else:
            print("用例不通过！")
            screenshot = s.failedScreenshotNamed("test_011_FundProductNoMoney")
            driver.save_screenshot(screenshot)

        time.sleep(3)

        driver.close()

        time.sleep(1)

        self.assertIn("买入失败", result)

    @unittest.skipIf(skip_test[11] == 1, '暂时跳过')
    @data(*da12)
    @unpack
    def test_012_FundProductNoCard(self, a, b, c):
        # 清理数据库，准备测试数据
        t = s.findUsername(a)
        if len(t) != 0:
            s.cleanDatabaseByUsername(a)
            s.addUsername(a)
        else:
            s.addUsername(a)
        userid = s.findIdByUserame(a)
        p = len(s.findBankcardById(userid))
        if p != 0:
            s.cleanCardById(userid)

        driver = webdriver.Chrome()

        driver.get("http://localhost:90/")

        driver.maximize_window()

        # 正常登录
        # 输入用户名
        driver.find_element(By.XPATH, "//input[@id='username']").send_keys(a)

        #  输入密码
        driver.find_element(By.XPATH, "//input[@id='password']").send_keys(b)

        # 点击登陆
        driver.find_element(By.XPATH, "//button[@id='login_btn']").click()
        time.sleep(1)

        # 点击个人理财
        driver.find_element(By.XPATH, "//i[@class='mdi mdi-square-inc-cash']").click()
        time.sleep(1)

        # 点击基金理财
        driver.find_element(By.LINK_TEXT, "基金理财").click()
        time.sleep(1)

        # 点击广发多元新兴股票
        driver.find_element(By.XPATH, "//button[@buybtnname='广发多元新兴股票']").click()
        time.sleep(2)

        # 输入支付密码
        driver.find_element(By.CSS_SELECTOR, ".layui-layer-content > #password").send_keys(c)
        time.sleep(1)

        # 点击确定
        driver.find_element(By.XPATH, "//a[@class='layui-layer-btn0']").click()
        time.sleep(2)

        #  获取实际标题结果
        result = driver.find_element(By.XPATH, "//div[@class='jconfirm-content']/div").text
        # print(len(driver.find_elements(By.XPATH, "//div[@class='jconfirm-content']")))

        if "请绑定银行卡" in result:
            print("用例通过！")
        else:
            print("用例不通过！")
            screenshot = s.failedScreenshotNamed("test_012_FundProductNoCard")
            driver.save_screenshot(screenshot)

        time.sleep(3)

        driver.close()

        time.sleep(1)

        self.assertIn("请绑定银行卡", result)

    @unittest.skipIf(skip_test[12] == 1, '暂时跳过')
    @data(*da13)
    @unpack
    def test_013_fundProductNoPwd(self, a, b, c):
        # 清理数据库，准备测试数据
        t = s.findUsername(a)
        if len(t) != 0:
            s.cleanDatabaseByUsername(a)
            s.addUsernameWithOutPayPwd(a)
        else:
            s.addUsernameWithOutPayPwd(a)
        p = len(s.findBankcardByNum(d))
        userid = s.findIdByUserame(a)
        if p == 0:
            s.addCompleteBankcard("中国银行", d, userid, 100000)
        else:
            s.cleanCardByNum(d)
            s.addCompleteBankcard("中国银行", d, userid, 100000)

        driver = webdriver.Chrome()

        driver.get("http://localhost:90/")

        driver.maximize_window()

        # 正常登录
        # 输入用户名
        driver.find_element(By.XPATH, "//input[@id='username']").send_keys(a)

        #  输入密码
        driver.find_element(By.XPATH, "//input[@id='password']").send_keys(b)

        # 点击登陆
        driver.find_element(By.XPATH, "//button[@id='login_btn']").click()
        time.sleep(1)

        # 点击个人理财
        driver.find_element(By.XPATH, "//i[@class='mdi mdi-square-inc-cash']").click()
        time.sleep(1)

        # 点击基金理财
        driver.find_element(By.LINK_TEXT, "基金理财").click()
        time.sleep(1)

        # 点击支付宝期限理财
        driver.find_element(By.XPATH, "//button[@buybtnname='广发多元新兴股票']").click()
        time.sleep(2)

        # 输入支付密码
        driver.find_element(By.CSS_SELECTOR, ".layui-layer-content > #password").send_keys(c)
        time.sleep(1)

        # 点击确定
        driver.find_element(By.XPATH, "//a[@class='layui-layer-btn0']").click()
        time.sleep(2)

        #  获取实际标题结果
        result = driver.find_element(By.XPATH, "//div[@class='jconfirm-content']/div").text

        # 还需要判断余额，后续添加
        if "请前往个人信息设置支付密码" in result:
            print("用例通过！")
        else:
            print("用例不通过！")
            screenshot = s.failedScreenshotNamed("test_013_fundProductNoPwd")
            driver.save_screenshot(screenshot)

        time.sleep(3)

        driver.close()

        time.sleep(1)

        self.assertIn("请前往个人信息设置支付密码", result)

    @unittest.skipIf(skip_test[13] == 1, '暂时跳过')
    @data(*da14)
    @unpack
    def test_014_FundProductManyCards(self, a, b, c):
        # 清理数据库，准备测试数据
        t = s.findUsername(a)
        if len(t) != 0:
            s.cleanDatabaseByUsername(a)
            s.addUsername(a)
        else:
            s.addUsername(a)
        userid = s.findIdByUserame(a)
        # 随机生成3个张银行卡号
        r = 3
        default_num = 0
        for k in range(r):
            n = s.generateNum(k + d + 1)
            s.cleanCardByNum(n)
            s.addCompleteBankcard(c, n, userid, 10000)
            # 指定默认银行卡号
            if k == 0:
                default_num = n
        s.setDefaultPayCard(userid, default_num)

        driver = webdriver.Chrome()

        driver.get("http://localhost:90/")

        driver.maximize_window()

        # 正常登录
        # 输入用户名
        driver.find_element(By.XPATH, "//input[@id='username']").send_keys(a)

        #  输入密码
        driver.find_element(By.XPATH, "//input[@id='password']").send_keys(b)

        # 点击登陆
        driver.find_element(By.XPATH, "//button[@id='login_btn']").click()
        time.sleep(1)

        # 点击个人理财
        driver.find_element(By.XPATH, "//i[@class='mdi mdi-square-inc-cash']").click()
        time.sleep(1)

        # 点击基金理财
        driver.find_element(By.LINK_TEXT, "基金理财").click()
        time.sleep(1)

        # 点击广发多元新兴股票
        driver.find_element(By.XPATH, "//button[@buybtnname='广发多元新兴股票']").click()
        time.sleep(2)

        # 输入支付密码
        driver.find_element(By.CSS_SELECTOR, ".layui-layer-content > #password").send_keys(c)
        time.sleep(1)

        # 点击确定
        driver.find_element(By.XPATH, "//a[@class='layui-layer-btn0']").click()
        time.sleep(2)

        #  获取实际标题结果
        result = driver.find_element(By.XPATH, "//div[@class='jconfirm-content']/div").text

        if "买入成功" in result:
            print("用例通过！")
        else:
            print("用例不通过！")
            screenshot = s.failedScreenshotNamed("test_014_FundProductManyCards")
            driver.save_screenshot(screenshot)

        time.sleep(3)

        driver.close()

        time.sleep(1)

        self.assertIn("买入失败", result)

    @unittest.skipIf(skip_test[14] == 1, '暂时跳过')
    @data(*da15)
    @unpack
    def test_015_FundProductManyCards2(self, a, b, c):
        # 清理数据库，准备测试数据
        t = s.findUsername(a)
        if len(t) != 0:
            s.cleanDatabaseByUsername(a)
            s.addUsername(a)
        else:
            s.addUsername(a)
        userid = s.findIdByUserame(a)
        # 随机生成3个张银行卡号
        r = 3
        default_num = 0
        for k in range(r):
            n = s.generateNum(k + d + 1)
            s.cleanCardByNum(n)
            s.addCompleteBankcard(c, n, userid, 10000)
            # 指定默认银行卡号
            if k == 1:
                default_num = n
        s.setDefaultPayCard(userid, default_num)
        driver = webdriver.Chrome()

        driver.get("http://localhost:90/")

        driver.maximize_window()

        # 正常登录
        # 输入用户名
        driver.find_element(By.XPATH, "//input[@id='username']").send_keys(a)

        #  输入密码
        driver.find_element(By.XPATH, "//input[@id='password']").send_keys(b)

        # 点击登陆
        driver.find_element(By.XPATH, "//button[@id='login_btn']").click()
        time.sleep(1)

        # 点击个人理财
        driver.find_element(By.XPATH, "//i[@class='mdi mdi-square-inc-cash']").click()
        time.sleep(1)

        # 点击基金理财
        driver.find_element(By.LINK_TEXT, "基金理财").click()
        time.sleep(1)

        # 点击广发多元新兴股票
        driver.find_element(By.XPATH, "//button[@buybtnname='广发多元新兴股票']").click()
        time.sleep(2)

        # 输入支付密码
        driver.find_element(By.CSS_SELECTOR, ".layui-layer-content > #password").send_keys(c)
        time.sleep(1)

        # 点击确定
        driver.find_element(By.XPATH, "//a[@class='layui-layer-btn0']").click()
        time.sleep(2)

        #  获取实际标题结果
        result = driver.find_element(By.XPATH, "//div[@class='jconfirm-content']/div").text

        if "买入成功" in result:
            print("用例通过！")
        else:
            print("用例不通过！")
            screenshot = s.failedScreenshotNamed("test_015_FundProductManyCards2")
            driver.save_screenshot(screenshot)

        time.sleep(3)

        driver.close()

        time.sleep(1)

        self.assertIn("买入失败", result)

    @unittest.skipIf(skip_test[15] == 1, '暂时跳过')
    @data(*da16)
    @unpack
    def test_016_FundProductNoCard(self, a, b, c):
        # 清理数据库，准备测试数据
        t = s.findUsername(a)
        if len(t) != 0:
            s.cleanDatabaseByUsername(a)
            s.addUsername(a)
        else:
            s.addUsername(a)
        userid = s.findIdByUserame(a)
        p = len(s.findBankcardById(userid))
        if p != 0:
            s.cleanCardById(userid)

        driver = webdriver.Chrome()

        driver.get("http://localhost:90/")

        driver.maximize_window()

        # 正常登录
        # 输入用户名
        driver.find_element(By.XPATH, "//input[@id='username']").send_keys(a)

        #  输入密码
        driver.find_element(By.XPATH, "//input[@id='password']").send_keys(b)

        # 点击登陆
        driver.find_element(By.XPATH, "//button[@id='login_btn']").click()
        time.sleep(1)

        # 点击个人理财
        driver.find_element(By.XPATH, "//i[@class='mdi mdi-square-inc-cash']").click()
        time.sleep(1)

        # 点击基金理财
        driver.find_element(By.LINK_TEXT, "基金理财").click()
        time.sleep(1)

        # 点击广发多元新兴股票
        driver.find_element(By.XPATH, "//button[@buybtnname='广发多元新兴股票']").click()
        time.sleep(2)

        # 输入支付密码
        driver.find_element(By.CSS_SELECTOR, ".layui-layer-content > #password").send_keys(c)
        time.sleep(1)

        # 点击确定
        driver.find_element(By.XPATH, "//a[@class='layui-layer-btn0']").click()
        time.sleep(2)

        #  获取实际标题结果
        result = driver.find_element(By.XPATH, "//div[@class='jconfirm-content']/div").text

        # 还需要判断余额，后续添加
        if "请绑定银行卡" in result:
            print("用例通过！")
        else:
            print("用例不通过！")
            screenshot = s.failedScreenshotNamed("test_016_FundProductNoCard")
            driver.save_screenshot(screenshot)

        time.sleep(3)

        driver.close()

        time.sleep(1)

        self.assertIn("请绑定银行卡", result)
